package com.sinoglobal.ningxia.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.sinoglobal.ningxia.R;
import com.sinoglobal.ningxia.beans.MyCouponsDataVo;
import com.sinoglobal.ningxia.http.ConnectionUtil;

import net.tsz.afinal.FinalBitmap;

import java.util.ArrayList;

/**
 * 
 * @author zbl
 * @createdate 2014-6-24 下午3:32:04
 * @Description:精品商城“我的”listview的adapter
 */
public class ShoppingListViewAdapter extends BaseAdapter {
	private Context context;
	private ArrayList<MyCouponsDataVo> enentsDataVos;

	public ShoppingListViewAdapter(Context context, ArrayList<MyCouponsDataVo> enentsDataVos) {
		super();
		this.context = context;
		this.enentsDataVos = enentsDataVos;
	}

	@Override
	public int getCount() {
		return enentsDataVos.size();
	}

	@Override
	public Object getItem(int position) {
		return enentsDataVos.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		if (convertView == null) {
			holder = new ViewHolder();
			convertView = LayoutInflater.from(context).inflate(R.layout.mallshop_viewpager_listview_item, null);
			holder.enentsItemImgUrl = (ImageView) convertView.findViewById(R.id.mycoupons_listview_itemImg);
			holder.enentsItemTitle = (TextView) convertView.findViewById(R.id.item_name);
			holder.enentsItemDate = (TextView) convertView.findViewById(R.id.mycoupons_itemdate);
			holder.enentsItemExpiryDate = (TextView) convertView.findViewById(R.id.mycoupons_item_usefuldate);
			holder.enentsItemIsGone = (ImageView) convertView.findViewById(R.id.mycoupons_item_isgone);
			holder.dateName=(TextView) convertView.findViewById(R.id.dateName);
			holder.use_date=(TextView) convertView.findViewById(R.id.use_date);
			convertView.setTag(holder);
		}

		holder = (ViewHolder) convertView.getTag();

		// 将传进来的MyCouponsDataVo中的Goods_img显示在imageview上
		FinalBitmap fb = FinalBitmap.create(context);
		fb.configLoadfailImage(R.drawable.default43);
		fb.configLoadingImage(R.drawable.default43);
		String URL = ConnectionUtil.localUrl + enentsDataVos.get(position).getGoods_img();
		fb.display(holder.enentsItemImgUrl, URL);

		// 根据MyCouponsDataVo的date_type来判断该活动是否过期 0过期 1没过期, 为0的文字都要置灰
		if ("0".equals(enentsDataVos.get(position).getDate_type())) {
			holder.enentsItemIsGone.setVisibility(View.VISIBLE);
			holder.enentsItemTitle.setTextColor(context.getResources().getColor(R.color.my_activity_item_text));
			holder.enentsItemDate.setTextColor(context.getResources().getColor(R.color.my_activity_item_text));
			holder.enentsItemExpiryDate.setTextColor(context.getResources().getColor(R.color.my_activity_item_text));
			holder.dateName.setTextColor(context.getResources().getColor(R.color.my_activity_item_text));
			holder.use_date.setTextColor(context.getResources().getColor(R.color.my_activity_item_text));
		} else {
			holder.enentsItemIsGone.setVisibility(View.GONE);
			holder.enentsItemTitle.setTextColor(context.getResources().getColor(R.color.shopping_goodsName_color));
			holder.enentsItemDate.setTextColor(context.getResources().getColor(R.color.mycoupons_itemdate_color));
			holder.enentsItemExpiryDate.setTextColor(context.getResources().getColor(R.color.mycoupons_itemdate_color));
			holder.dateName.setTextColor(context.getResources().getColor(R.color.mycoupons_itemdate_color));
			holder.use_date.setTextColor(context.getResources().getColor(R.color.mycoupons_itemdate_color));
			
		}
		holder.enentsItemTitle.setText(enentsDataVos.get(position).getGoods_name());
		holder.enentsItemDate.setText(enentsDataVos.get(position).getGoods_time());
		holder.enentsItemExpiryDate.setText(enentsDataVos.get(position).getTime_str());
		return convertView;
	}

	class ViewHolder {
		ImageView enentsItemIsGone;// 该条活动是否过期
		ImageView enentsItemImgUrl;// 图片的显示
		TextView enentsItemTitle;// 活动名称
		TextView enentsItemDate;// 参加日期
		TextView enentsItemExpiryDate;// 有效日期
		TextView dateName;
		TextView use_date;
		

	}

}
